package com.example.nio.netty.client;

import com.example.nio.netty.protoco.response.LoginResponse;
import com.example.nio.netty.session.Attributes;
import com.example.nio.netty.session.Session;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

public class LoginHandler extends SimpleChannelInboundHandler<LoginResponse> {

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, LoginResponse msg) throws Exception {
        if (msg.getResult()) {
            System.out.println("登陆成功");
            System.out.println(msg.getUserId());
        }
        ctx.channel().attr(Attributes.attributeKey).set(new Session(msg.getUserId(), msg.getUserName()));
    }
    @Override
    public void channelInactive(ChannelHandlerContext ctx) {
        System.out.println("客户端连接被关闭!");
    }
}
